*********************************************************************
*** Political costs of trade war tariffs 
*** Edward D. Mansfield & Omer Solodoch 
*** Replication code for analysis of the KFF poll  
*** Note: replicators must install the following packages from the SSC Archive:
*** ssc install ebalance
*** ssc install outtable
*** ssc install coefplot
*** ssc install esttab
*** ssc install interflex
*********************************************************************

clear all
set mem 600m
set matsize 800	
version 17
set more off
set logtype text
set scheme s1mono
*** Set working directory
capture cd "XXXX"
*** Load dataset
use "MSJOP_KFF.dta", clear



****************************************
***** Table 2: Effect heterogeneity
****************************************
estimates clear
** (1)
eststo: areg trumpapp_4 post_escalation educ4 inlaborforce median_income emp_chn_target_cum_juneQr4 i.raceethnicity pid3 i.recage3 gender2  [aw=weight] if prepaidsamp==0, absorb(sstate) 
estadd local controls "\checkmark", replace
estadd local sfixedef "\checkmark", replace
** (2)
eststo: areg trumpapp_4 post_escalation treat_collgrad educ4 inlaborforce median_income emp_chn_target_cum_juneQr4 i.raceethnicity pid3 i.recage3 gender2  [aw=weight] if prepaidsamp==0, absorb(sstate) 
estadd local controls "\checkmark", replace
estadd local sfixedef "\checkmark", replace
** (3)
eststo: areg trumpapp_4 post_escalation treat_laborforce educ4 inlaborforce median_income emp_chn_target_cum_juneQr4 i.raceethnicity pid3 i.recage3 gender2  [aw=weight] if prepaidsamp==0, absorb(sstate) 
estadd local controls "\checkmark", replace
estadd local sfixedef "\checkmark", replace
** (4)
eststo: areg trumpapp_4 post_escalation treat_medincome educ4 inlaborforce median_income emp_chn_target_cum_juneQr4 i.raceethnicity pid3 i.recage3 gender2  [aw=weight] if prepaidsamp==0, absorb(sstate) 
estadd local controls "\checkmark", replace
estadd local sfixedef "\checkmark", replace
** (5)
eststo: areg trumpapp_4 post_escalation treat_targeted educ4 inlaborforce median_income emp_chn_target_cum_juneQr4 i.raceethnicity pid3 i.recage3 gender2  [aw=weight] if prepaidsamp==0, absorb(sstate) 
estadd local controls "\checkmark", replace
estadd local sfixedef "\checkmark", replace
** (6)
eststo: areg trumpapp_4 post_escalation treat_rep educ4 inlaborforce median_income emp_chn_target_cum_juneQr4 i.raceethnicity pid3 i.recage3 gender2  [aw=weight] if prepaidsamp==0, absorb(sstate) 
estadd local controls "\checkmark", replace
estadd local sfixedef "\checkmark", replace
** export table
 esttab est1 est2 est3 est4 est5 est6, ///
 keep(post_escalation treat_collgrad treat_laborforce treat_medincome treat_targeted treat_rep) ///
order(post_escalation treat_collgrad treat_laborforce treat_medincome treat_targeted treat_rep) ///
 se(3) b(3) replace star(+ 0.10 * 0.05 ** 0.01) label  nonotes nogaps  ///
 nodepvars mtitles("" "" "" "" "" "") ///
 s(controls sfixedef N r2, fmt(0 0 0 3) label("Covariates" "State FE" "Observations" "R-squared"))

**************************************************************
***** Table A-17: Effect heterogeneity, full tabular results
**************************************************************
  esttab est1 est2 est3 est4 est5 est6, ///
keep(post_escalation treat_collgrad treat_laborforce treat_medincome treat_targeted treat_rep educ4 inlaborforce median_income emp_chn_target_cum_juneQr4 pid3 *.raceethnicity *.recage3 gender2) ///
order(post_escalation treat_collgrad treat_laborforce treat_medincome treat_targeted treat_rep educ4 inlaborforce median_income emp_chn_target_cum_juneQr4 pid3 *.raceethnicity *.recage3 gender2) ///
 se(3) b(3) replace star(+ 0.10 * 0.05 ** 0.01) label  nonotes nogaps  ///
 nodepvars mtitles("" "" "" "" "" "") ///
 s(controls sfixedef N r2, fmt(0 0 0 3) label("Covariates" "State FE" "Observations" "R-squared"))

 
************************************************************************************************
** Table A-5: balance over exposure to tariffs
************************************************************************************************
tabstat emp_chn_target_cum_june if prepaidsamp==0, stats(mean semean median min max) format(%9.2fc) by(post_escalation) not

tabstat emp_chn_target_cum_juneQr4 if prepaidsamp==0, stats(mean semean median min max) format(%9.2fc) by(post_escalation) not

************************************************************************************************
** Table A-6: sample, entropy balancing, and SEs
************************************************************************************************
qui ebalance post_escalation  emp_chn_target_cum_june i.pid i.education i.raceethnicity  Age gender2 i.urban if prepaidsamp==0, targets(2)
lab var Zemp_chn_target_cum_june "Targeted by Chinese tariffs (std)"

estimates clear
** 1 full sample
eststo: areg TRUMPAPP1 post_escalation  Zemp_chn_target_cum_june i.pid i.education i.raceethnicity  Age gender2 i.urban [aw=weight], absorb(sstate) 
estadd local controls "\checkmark", replace
estadd local sfixedef "\checkmark", replace
estadd local stderrs "OLS", replace
estadd local smpl "full", replace


** 2 random sample
eststo: areg TRUMPAPP1 post_escalation  Zemp_chn_target_cum_june i.pid i.education i.raceethnicity  Age gender2 i.urban [aw=weight] if prepaidsamp==0, absorb(sstate) 
estadd local controls "\checkmark", replace
estadd local sfixedef "\checkmark", replace
estadd local stderrs "OLS", replace
estadd local smpl "random", replace

** 3 re-weighted sample
ebalance post_escalation  emp_chn_target_cum_june i.pid i.education i.raceethnicity  Age gender2 i.urban if prepaidsamp==0, targets(2)

eststo: areg TRUMPAPP1 post_escalation  Zemp_chn_target_cum_june i.pid i.education i.raceethnicity  Age gender2 i.urban [aweight=_webal] if prepaidsamp==0, absorb(sstate)
estadd local controls "\checkmark", replace
estadd local sfixedef "\checkmark", replace
estadd local stderrs "OLS", replace
estadd local smpl "reweighted", replace

** 4 re-weighted sample, robust SEs
eststo: areg TRUMPAPP1 post_escalation  Zemp_chn_target_cum_june i.pid i.education i.raceethnicity  Age gender2 i.urban [aweight=_webal] if prepaidsamp==0, absorb(sstate) robust
estadd local controls "\checkmark", replace
estadd local sfixedef "\checkmark", replace
estadd local stderrs "robust", replace
estadd local smpl "reweighted", replace

** 5 re-weighted sample, robust SEs clustered by county
eststo: areg TRUMPAPP1 post_escalation  Zemp_chn_target_cum_june i.pid i.education i.raceethnicity  Age gender2 i.urban [aweight=_webal] if prepaidsamp==0, absorb(sstate) robust cl(cty_fips)
estadd local controls "\checkmark", replace
estadd local sfixedef "\checkmark", replace
estadd local stderrs "clustered", replace
estadd local smpl "reweighted", replace


 esttab est1 est2 est3 est4 est5, keep(post_escalation Zemp_chn_target_cum_june) ///
order(post_escalation Zemp_chn_target_cum_june) ///
 se(3) b(3) replace star(+ 0.10 * 0.05 ** 0.01) label  nonotes nogaps mtitles("" "" "" "" "")  ///
 s(controls sfixedef smpl stderrs N r2, fmt(0 0 0 0 0 3) label("Covariates" "State FE" "Sample" "Standard Errors" "Observations" "R-squared"))


**************************************************************
***** Table A-8: post-escalation effect by cutoff selection, KFF
**************************************************************
label var post_escalation "Post-escalation (June 16)"
estimates clear
eststo: areg TRUMPAPP1 post_escalation15 i.education i.employment i.income i.raceethnicity i.pid i.recage3 i.gender2 i.urban [aweight=weight] if prepaidsamp==0, absorb(sstate) 
estadd local controls "\checkmark", replace
estadd local sfixedef "\checkmark", replace
estadd local june15 "treated", replace

eststo: areg TRUMPAPP1 post_escalation i.education i.employment i.income i.raceethnicity i.pid i.recage3 i.gender2 i.urban [aweight=weight] if day_id!=615 &  prepaidsamp==0, absorb(sstate) 
estadd local controls "\checkmark", replace
estadd local sfixedef "\checkmark", replace
estadd local june15 "missing", replace

eststo: areg TRUMPAPP1 post_escalation i.education i.employment i.income i.raceethnicity i.pid i.recage3 i.gender2 i.urban [aweight=weight] if prepaidsamp==0, absorb(sstate) 
estadd local controls "\checkmark", replace
estadd local sfixedef "\checkmark", replace
estadd local june15 "control", replace

 esttab est1 est2 est3, keep(post_escalation15 post_escalation) ///
order(post_escalation15 post_escalation) ///
 se(3) b(3) replace star(+ 0.10 * 0.05 ** 0.01) label  nonotes nogaps  ///
 s(controls sfixedef june15 N r2, fmt(0 0 0 0 3) label("Covariates" "State FE" "June 15 coded as:" "Observations" "R-squared"))

********************************************************************************************************
***** Table A-10: post-escalation effect by alternative coding of "don't know" responses, KFF
********************************************************************************************************
label var post_escalation "Post-escalation"
estimates clear
eststo: areg TRUMPAPP1 post_escalation i.education i.employment i.raceethnicity i.pid i.recage3 i.gender2 i.urban [aweight=weight], absorb(sstate)
estadd local controls "\checkmark", replace
estadd local sfixedef "\checkmark", replace
estadd local dkcoded "0", replace
estadd local smpl "full", replace


eststo: areg TRUMPAPP1 post_escalation i.education i.employment i.raceethnicity i.pid i.recage3 i.gender2 i.urban [aweight=weight] if  prepaidsamp==0, absorb(sstate)
estadd local controls "\checkmark", replace
estadd local sfixedef "\checkmark", replace
estadd local dkcoded "0", replace
estadd local smpl "random", replace

eststo: areg TRUMPAPP1 post_escalation i.education i.employment i.raceethnicity i.pid i.recage3 i.gender2 i.urban [aweight=weight] if trumpapp_4<=4 &  prepaidsamp==0, absorb(sstate)
estadd local controls "\checkmark", replace
estadd local sfixedef "\checkmark", replace
estadd local dkcoded "missing", replace
estadd local smpl "random", replace

eststo: areg trumpapp_4 post_escalation i.education i.employment i.raceethnicity i.pid i.recage3 i.gender2 i.urban [aweight=weight] if  prepaidsamp==0, absorb(sstate)
estadd local controls "\checkmark", replace
estadd local sfixedef "\checkmark", replace
estadd local dkcoded "missing", replace
estadd local smpl "random", replace

eststo: areg trumpapp_5 post_escalation i.education i.employment i.raceethnicity i.pid i.recage3 i.gender2 i.urban [aweight=weight] if prepaidsamp==0, absorb(sstate)
estadd local controls "\checkmark", replace
estadd local sfixedef "\checkmark", replace
estadd local dkcoded "midpoint (3)", replace
estadd local smpl "random", replace


 esttab est1 est2 est3 est4 est5, keep(post_escalation) ///
order(post_escalation) ///
 se(3) b(3) replace star(+ 0.10 * 0.05 ** 0.01) label  nonotes nogaps mtitles("Approve (0/1)" "Approve (0/1)" "Approve (0/1)" "Approve (1-4)" "Approve (1-5)")  ///
 s(controls sfixedef dkcoded smpl N r2, fmt(0 0 0 0 0 3) label("Covariates" "State FE" "DK coded as" "Sample" "Observations" "R-squared"))

**************************************************************
***** Table A-12: Effect heterogeneity, ordered probit estimates
**************************************************************
estimates clear
** (1)
eststo: oprobit trumpapp_4 post_escalation educ4 inlaborforce median_income emp_chn_target_cum_juneQr4 i.raceethnicity pid3 i.recage3 gender2 i.sstate [aw=weight] if prepaidsamp==0
estadd local controls "\checkmark", replace
estadd local sfixedef "\checkmark", replace
** (2)
eststo: oprobit trumpapp_4 post_escalation treat_collgrad educ4 inlaborforce median_income emp_chn_target_cum_juneQr4 i.raceethnicity pid3 i.recage3 gender2  i.sstate [aw=weight] if prepaidsamp==0
estadd local controls "\checkmark", replace
estadd local sfixedef "\checkmark", replace
** (3)
eststo: oprobit trumpapp_4 post_escalation treat_laborforce educ4 inlaborforce median_income emp_chn_target_cum_juneQr4 i.raceethnicity pid3 i.recage3 gender2 i.sstate [aw=weight] if prepaidsamp==0
estadd local controls "\checkmark", replace
estadd local sfixedef "\checkmark", replace
** (4)
eststo: oprobit trumpapp_4 post_escalation treat_medincome educ4 inlaborforce median_income emp_chn_target_cum_juneQr4 i.raceethnicity pid3 i.recage3 gender2  i.sstate [aw=weight] if prepaidsamp==0
estadd local controls "\checkmark", replace
estadd local sfixedef "\checkmark", replace
** (5)
eststo: oprobit trumpapp_4 post_escalation treat_targeted educ4 inlaborforce median_income emp_chn_target_cum_juneQr4 i.raceethnicity pid3 i.recage3 gender2 i.sstate [aw=weight] if prepaidsamp==0
estadd local controls "\checkmark", replace
estadd local sfixedef "\checkmark", replace
** (6)
eststo: oprobit trumpapp_4 post_escalation treat_rep educ4 inlaborforce median_income emp_chn_target_cum_juneQr4 i.raceethnicity pid3 i.recage3 gender2 i.sstate [aw=weight] if prepaidsamp==0
estadd local controls "\checkmark", replace
estadd local sfixedef "\checkmark", replace
** export table
 esttab est1 est2 est3 est4 est5 est6, ///
keep(post_escalation treat_collgrad treat_laborforce treat_medincome treat_targeted treat_rep) ///
order(post_escalation treat_collgrad treat_laborforce treat_medincome treat_targeted treat_rep) ///
 se(3) b(3) replace star(+ 0.10 * 0.05 ** 0.01) label   nonotes nogaps  ///
 s(controls sfixedef N r2_p, fmt(0 0 0 3) label("Covariates" "State FE" "Observations" "Pseudo R-squared"))

 
********************************************************************************************************
***** Figure A-3: effect by county-level exposure to tariffs
********************************************************************************************************
*(a) Chinese tariffs, in June
interflex trumpapp_4 post_escalation emp_chn_target_juneP gender2 educ2 educ3 educ4 raceethnicity2 raceethnicity3 raceethnicity4 pid2 pid3  ,  ylabel(Trump approval) xlabel(exposure to Chinese tariffs in June) dlabel(post-escalation)

*(b) Chinese tariffs, by June
interflex trumpapp_4 post_escalation emp_chn_target_cum_juneP gender2 educ2 educ3 educ4 raceethnicity2 raceethnicity3 raceethnicity4 pid2 pid3  ,   ylabel(Trump approval) xlabel(exposure to Chinese tariffs by June) dlabel(post-escalation)

*(b) All tariffs, by June
interflex trumpapp_4 post_escalation emp_all_target_juneP gender2 educ2 educ3 educ4 raceethnicity2 raceethnicity3 raceethnicity4 pid2 pid3  ,   ylabel(Trump approval) xlabel(exposure to all tariffs by June) dlabel(post-escalation)
********************************************************************************************************